<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span style="font-weight: bold">阈值设置</span>
      <el-button style="float: right; padding: 3px 0" type="text" @click="refreshThresholdVal"><i class="fa fa-refresh" aria-hidden="true"></i></el-button>
    </div>
    <div class="text item">
      <div style="display: flex">
        <label class="font-postion">温度下限:</label>
        <el-input class="threshold_value" placeholder="请输入内容" v-model="minTem" clearable></el-input>
        <el-button type="info" @click="setThresholdVal(1)"><i class="fa fa-cog" aria-hidden="true"></i>设置</el-button>
      </div>
      <div style="display: flex;margin-top:1rem;">
        <label class="font-postion">温度上限:</label>
        <el-input class="threshold_value" placeholder="请输入内容" v-model="maxTem" clearable></el-input>
        <el-button type="info" @click="setThresholdVal(2)"><i class="fa fa-cog" aria-hidden="true"></i>设置</el-button>
      </div>
      <div style="display: flex;margin-top:1rem;">
        <label class="font-postion">电流/电压下限:</label>
        <el-input class="threshold_value" placeholder="请输入内容" v-model="minAV" clearable></el-input>
        <el-button type="info" @click="setThresholdVal(3)"><i class="fa fa-cog" aria-hidden="true"></i>设置</el-button>
      </div>
      <div style="display: flex;margin-top:1rem;">
        <label class="font-postion">电流/电压上限:</label>
        <el-input class="threshold_value" placeholder="请输入内容" v-model="maxAV" clearable></el-input>
        <el-button type="info" @click="setThresholdVal(4)"><i class="fa fa-cog" aria-hidden="true"></i>设置</el-button>
      </div>
      <div style="display: flex;margin-top:1rem;">
        <label class="font-postion">AD下限:</label>
        <el-input class="threshold_value" placeholder="请输入内容" v-model="minMnl" clearable></el-input>
        <el-button type="info" @click="setThresholdVal(5)"><i class="fa fa-cog" aria-hidden="true"></i>设置</el-button>
      </div>
      <div style="display: flex;margin-top:1rem;">
        <label class="font-postion">AD上限:</label>
        <el-input class="threshold_value" placeholder="请输入内容" v-model="maxMnl" clearable></el-input>
        <el-button type="info" @click="setThresholdVal(6)"><i class="fa fa-cog" aria-hidden="true"></i>设置</el-button>
      </div>
      <div style="display: flex;margin-top:1rem;">
        <label class="font-postion">误差值:</label>
        <el-input class="threshold_value" placeholder="请输入内容" v-model="errorVal" clearable></el-input>
        <el-button type="info" @click="setThresholdVal(7)"><i class="fa fa-cog" aria-hidden="true"></i>设置</el-button>
      </div>
    </div>
  </el-card>
</template>

<script>
import {listInfo, updateInfo} from "@/api/system/argument";
export default {
  name: "thresholdVal",
  data() {
    return {
      minTem: '',
      maxTem: '',
      minAV: '',
      maxAV: '',
      minMnl: '',
      maxMnl: '',
      errorVal:''
    }
  },
  created() {
    this.getList();
  },
  methods: {
    setThresholdVal(type){
      let data = null;
      if(type===1){
        data = type + ',' +this.minTem;
      }else if(type===2){
        data = type + ',' +this.maxTem;
      }else if(type===3){
        data = type + ',' +this.minAV;
      }else if(type===4){
        data = type + ',' +this.maxAV;
      }else if(type===5){
        data = type + ',' +this.minMnl;
      }else if(type===6){
        data = type + ',' +this.maxMnl;
      }else if(type===7){
        data = type + ',' +this.errorVal;
      }
      updateInfo(data).then(response=>{
        this.$modal.msgSuccess(response.msg);
      })
    },
    refreshThresholdVal(){
      this.getList();
    },
    getList() {
      this.loading = true;
      listInfo().then(response => {
        if(response.data.length>0){
          response.data.forEach(result=>{
            if(result.thresholdCode==='minTem'){
              this.minTem = result.thresholdValue;
            }else if(result.thresholdCode==='maxTem'){
              this.maxTem = result.thresholdValue;
            }else if(result.thresholdCode==='minAV'){
              this.minAV = result.thresholdValue;
            }else if(result.thresholdCode==='maxAV'){
              this.maxAV = result.thresholdValue;
            }else if(result.thresholdCode==='minMnl'){
              this.minMnl = result.thresholdValue;
            }else if(result.thresholdCode==='maxMnl'){
              this.maxMnl = result.thresholdValue;
            }else if(result.thresholdCode==='errorVal'){
              this.errorVal = result.thresholdValue;
            }
          })
        }
        this.loading = false;
      });
      this.$modal.msgSuccess("刷新成功！");
    },
  }
}
</script>

<style scoped>
.font-postion{
  display:flex;
  width:40%;
  align-items: center;
  justify-content: right;
  margin-right:1rem;
}
.text {
  font-size: 14px;
}
.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

.box-card {
  width: 480px;
}
</style>
